home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / 4dtnt.zip / FRAC.BTM < prev    next >
Text File  |  1991-11-03  |  2KB  |  46 lines

  1.  
  2. rem 4DOS provides an internal function, @int[], but not a way
  3. rem to get the fractional part of a number.  Here's a tool.
  4. rem This is also a simple illustration of modifying an environment
  5. rem variable whose name is passed in.
  6.  
  7. rem The key lesson in this example is the use and modification of 
  8. rem the VALUE of a variable given its NAME in %1.
  9.  
  10. rem This .btm is meant to be CALLed from another batch file.
  11. rem
  12. if "%1" == "" .or. "%[%1]" == "" goto help
  13. rem  !                !
  14. rem  !                The VALUE of variable "name"
  15. rem  The NAME of a variable
  16.  
  17.  
  18. rem The following sets the given variable to the fractional part.
  19. rem Note the function nesting.
  20.  
  21. rem The third argument of @substr is omitted, referring to the rest
  22. rem of the string by default [4DOS 4.0 enhancement]
  23.                    
  24. rem The length of the integer portion is used as the offset into the
  25. rem string to begin and extract the fraction portion.
  26.  
  27. set %1=%@substr[%[%1],%@len[%@int[%[%1]]]]
  28. :exit
  29. quit 0
  30.  
  31. :help
  32. rem
  33. rem  Note the use of the name of the command the user typed, even
  34. rem  though this .btm file may have been renamed.
  35. rem
  36. echo Usage: %@name[%0]  var 
  37. echo.
  38. echo   var =  Any environment variable whose value is the input
  39. echo New value returned in var, replacing original value.
  40. echo New value is the fraction portion of a floating point value.
  41. echo Example: set foo=12.345
  42. echo          %@name[%0] foo
  43. echo          set foo
  44. echo          .345
  45. quit 4
  46.